﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using WMS6.Common;
    using WMS6.DALFactory;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class OrdersBLL
    {
        private static readonly IBillingEntityDA billingEntityDA = DataAccess.CreateBillingEntityDA();
        private static readonly ICarrierDA carrierDA = DataAccess.CreateCarrierDA();
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private string currentWhName;
        private static readonly ICustomerDA customerDA = DataAccess.CreateCustomerDA();
        private List<string> dataBaseID;
        private static readonly IEdiLogDA edilogDA = DataAccess.CreateEdiLogDA();
        private static readonly IIntransitDA IntransitDA = DataAccess.CreateIntransitDA();
        private static readonly IIntransitDetailDA IntransitDetailDA = DataAccess.CreateIntransitDetailDA();
        private static readonly ILotAttributeDA lotAttributeDA = DataAccess.CreateLotAttributeDA();
        private static readonly IManPowerResourceDA manpowerResourceDA = DataAccess.CreateManPowerResourceDA();
        private static readonly IOrderDetailDA orderDetailDA = DataAccess.CreateOrderDetailDA();
        private static readonly IOrdersDA ordersDA = DataAccess.CreateOrdersDA();
        private static readonly IOwnerDA ownerDA = DataAccess.CreateOwnerDA();
        private static readonly IPackDA packDA = DataAccess.CreatePackDA();
        private static readonly IPickDetailDA pickDetailDA = DataAccess.CreatePickDetailDA();
        private static readonly IPortDA portDA = DataAccess.CreatePortDA();
        private static readonly IPreallocatePickDetailDA preallocatePickDetailDA = DataAccess.CreatePreallocatePickDetailDA();
        private PubParasInfo pubParasInfo;
        private static readonly IShipmentContainerDA shipmentContainerDA = DataAccess.CreateShipmentContainerDA();
        private static readonly ISkuDA skuDA = DataAccess.CreateSkuDA();
        private static readonly IVendorDA vendorDA = DataAccess.CreateVendorDA();
        private static readonly IWaveDA waveDA = DataAccess.CreateWaveDA();
        private static readonly IWaveDetailDA waveDetailDA = DataAccess.CreateWaveDetailDA();

        public OrdersBLL()
        {
            this.pubParasInfo = null;
            this.currentWhName = string.Empty;
        }

        public OrdersBLL(string currentWH)
        {
            this.pubParasInfo = null;
            this.currentWhName = string.Empty;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.currentWhName = currentWH;
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public OrdersBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            this.currentWhName = string.Empty;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.currentWhName = tempPubParasInfo.CurrentWH;
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public string CheckExternalIDExist(string externalID)
        {
            if (ordersDA.GetOrdersByExternalID(externalID, this.dataBaseID[0], this.pubParasInfo) != null)
            {
                return "Y";
            }
            return "N";
        }

        public string ConfirmShippingReviewByOrderID(List<OrdersInfo> orderList)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string ordersID = string.Empty;
            try
            {
                WaveBLL wavebll = new WaveBLL(this.pubParasInfo);
                foreach (OrdersInfo info in orderList)
                {
                    if (!string.IsNullOrEmpty(info.OrderID) && (ordersDA.UpdateOrdersStatus(dataBase, tran, info.OrderID, OrderStatus.Reviewed, this.pubParasInfo.UserID, this.dataBaseID[0]) > 0))
                    {
                        orderDetailDA.UpdateOrderDetailStatus(dataBase, tran, info.OrderID, OrderStatus.Reviewed, this.pubParasInfo.UserID, this.dataBaseID[0]);
                        ordersID = ordersID + info.OrderID + ";";
                        waveDetailDA.UpdateWaveDetailStatusByOrderID(dataBase, tran, info.OrderID, OrderStatus.Reviewed, this.pubParasInfo.UserID, this.dataBaseID[0]);
                        wavebll.UpdateWaveStatusByOrderID(dataBase, tran, info.OrderID);
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ordersID;
        }

        public string DeleteOrders(List<string> orderID)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            List<string> IntransitIDs = new List<string>();
            string temp = "";
            try
            {
                List<OrdersInfo> ordersInfos = new List<OrdersInfo>();
                OrdersInfo ordersInfo = null;
                foreach (string id in orderID)
                {
                    ordersInfo = ordersDA.GetOrdersByID(dataBase, tran, id, this.dataBaseID[0], this.pubParasInfo);
                    ordersInfos.Add(ordersInfo);
                }
                IntransitDetailDA.DeleteIntransitDetailByOrderID(dataBase, tran, orderID, this.dataBaseID[0]);
                IntransitDA.DeleteIntransitByOrderID(dataBase, tran, orderID, this.dataBaseID[0]);
                orderDetailDA.DeleteOrderDetail(dataBase, tran, orderID, this.dataBaseID);
                if (ordersDA.DeleteOrders(dataBase, tran, orderID, this.dataBaseID) > 0)
                {
                    int i;
                    List<string> orderType = new List<string>();
                    List<string> soOrderID = new List<string>();
                    for (i = 0; i < orderID.Count; i++)
                    {
                        orderType.Add("SO");
                        soOrderID.Add(orderID[i]);
                    }
                    manpowerResourceDA.DeleteManPowerResource(dataBase, tran, soOrderID, orderType, this.dataBaseID[0]);
                    for (i = 0; i < orderID.Count; i++)
                    {
                        auditDataBLL.InsertAuditData<OrdersInfo>(dataBase, tran, ordersInfos[i], null, AuditAction.Delete, this.pubParasInfo.UserID, "ORDERS", this.dataBaseID[i]);
                        temp = temp + orderID[i] + ",";
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            if (temp.Length > 0)
            {
                return temp.Substring(0, temp.Length - 1);
            }
            return temp;
        }

        public DataSet GetOrdersByQueryEntity(OrdersQueryEntity ordersQuery)
        {
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(ordersQuery.OrderID))
            {
                sqlWhere.Add(" O.ORDER_ID " + ordersQuery.OrderID);
            }
            if (!string.IsNullOrEmpty(ordersQuery.OwnerID))
            {
                sqlWhere.Add(" O.OWNER_ID " + ordersQuery.OwnerID);
            }
            if (!string.IsNullOrEmpty(ordersQuery.OrderDate))
            {
                sqlWhere.Add(ordersQuery.OrderDate.Replace("@OrderDate@", " O.ORDER_DATE "));
            }
            if (!string.IsNullOrEmpty(ordersQuery.RequestedShipDate))
            {
                sqlWhere.Add(ordersQuery.RequestedShipDate.Replace("@RequestedShipDate@", " O.REQUESTED_SHIP_DATE "));
            }
            if (!string.IsNullOrEmpty(ordersQuery.ActualShipDate))
            {
                sqlWhere.Add(ordersQuery.ActualShipDate.Replace("@ActualShipDate@", " O.ACTUAL_SHIP_DATE "));
            }
            if (!string.IsNullOrEmpty(ordersQuery.DeliveryDate))
            {
                sqlWhere.Add(ordersQuery.DeliveryDate.Replace("@DeliveryDate@", " O.DELIVERY_DATE "));
            }
            if (!string.IsNullOrEmpty(ordersQuery.DepartureDate))
            {
                sqlWhere.Add(ordersQuery.DepartureDate.Replace("@DepartureDate@", " O.DEPARTURE_DATE "));
            }
            if (!string.IsNullOrEmpty(ordersQuery.Priority))
            {
                sqlWhere.Add(" O.PRIORITY " + ordersQuery.Priority);
            }
            if (!string.IsNullOrEmpty(ordersQuery.Type))
            {
                sqlWhere.Add(" O.TYPE " + ordersQuery.Type);
            }
            if (!string.IsNullOrEmpty(ordersQuery.OrderGroup))
            {
                sqlWhere.Add(" O.ORDER_GROUP " + ordersQuery.OrderGroup);
            }
            if (!string.IsNullOrEmpty(ordersQuery.ExternOrderID))
            {
                sqlWhere.Add(" O.EXTERN_ORDER_ID " + ordersQuery.ExternOrderID);
            }
            if (!string.IsNullOrEmpty(ordersQuery.ConsigneeID))
            {
                sqlWhere.Add(" O.CONSIGNEE_ID " + ordersQuery.ConsigneeID);
            }
            if (!string.IsNullOrEmpty(ordersQuery.BillToID))
            {
                sqlWhere.Add(" O.BILL_TO_ID " + ordersQuery.BillToID);
            }
            if (!string.IsNullOrEmpty(ordersQuery.BatchFlag))
            {
                sqlWhere.Add(" O.BATCH_FLAG " + ordersQuery.BatchFlag);
            }
            if (!string.IsNullOrEmpty(ordersQuery.ShipTogether))
            {
                sqlWhere.Add(" O.SHIP_TOGETHER " + ordersQuery.ShipTogether);
            }
            if (!string.IsNullOrEmpty(ordersQuery.OrderValue))
            {
                sqlWhere.Add(" O.ORDER_VALUE " + ordersQuery.OrderValue);
            }
            if (!string.IsNullOrEmpty(ordersQuery.UpdateSource))
            {
                sqlWhere.Add(" O.UPDATE_SOURCE " + ordersQuery.UpdateSource);
            }
            if (!string.IsNullOrEmpty(ordersQuery.IsActive))
            {
                sqlWhere.Add(" O.IS_ACTIVE " + ordersQuery.IsActive);
            }
            if (!string.IsNullOrEmpty(ordersQuery.Door))
            {
                sqlWhere.Add(" O.DOOR " + ordersQuery.Door);
            }
            if (!string.IsNullOrEmpty(ordersQuery.Route))
            {
                sqlWhere.Add(" O.ROUTE " + ordersQuery.Route);
            }
            if (!string.IsNullOrEmpty(ordersQuery.Stop))
            {
                sqlWhere.Add(" O.Stop " + ordersQuery.Stop);
            }
            if (!string.IsNullOrEmpty(ordersQuery.Status))
            {
                sqlWhere.Add(" O.Status " + ordersQuery.Status);
            }
            if (!string.IsNullOrEmpty(ordersQuery.ReferenceNum))
            {
                sqlWhere.Add(" O.REFERENCE_NUM " + ordersQuery.ReferenceNum);
            }
            if (!string.IsNullOrEmpty(ordersQuery.WaveID))
            {
                sqlWhere.Add(" WD.WAVE_ID " + ordersQuery.WaveID);
            }
            if (!string.IsNullOrEmpty(ordersQuery.DriverName))
            {
                sqlWhere.Add(" O.DRIVER_NAME " + ordersQuery.DriverName);
            }
            if (!string.IsNullOrEmpty(ordersQuery.TransportationMode))
            {
                sqlWhere.Add(" O.TRANSPORTATION_MODE " + ordersQuery.TransportationMode);
            }
            if (!string.IsNullOrEmpty(ordersQuery.Operator))
            {
                sqlWhere.Add(" O.OPERATOR " + ordersQuery.Operator);
            }
            if (!string.IsNullOrEmpty(ordersQuery.OperatingDate))
            {
                sqlWhere.Add(ordersQuery.OperatingDate.Replace("@OperatingDate@", " O.OPERATINGDATE "));
            }
            if (!string.IsNullOrEmpty(ordersQuery.DeclarationsType))
            {
                sqlWhere.Add(" O.DECLARATIONS_TYPE = '" + ordersQuery.DeclarationsType + "'");
            }
            return ordersDA.GetOrdersByQueryList(sqlWhere, ordersQuery, this.dataBaseID[0], this.pubParasInfo);
        }

        public OrdersInfo GetOrdersInfoAndDetailListByID(string ordersID, string ContainerID)
        {
            OrdersInfo ordersInfo = ordersDA.GetOrdersByID(ordersID, this.dataBaseID[0], this.pubParasInfo);
            if (ordersInfo != null)
            {
                ordersInfo.OrderDetailInfos = orderDetailDA.GetOrderDetailListByOrderIDAndContainerID(ordersInfo.OrderID, ContainerID, this.dataBaseID[0], this.pubParasInfo);
                ordersInfo.ShipmentContainerInfos = shipmentContainerDA.GetShipmentContainerListByOrderID(ordersInfo.OrderID, ContainerID, this.dataBaseID[0]);
                InboundHelper inboundHelper = new InboundHelper();
                OutboundMgtBLL outBoundMgtBll = new OutboundMgtBLL();
                if ((ordersInfo.OrderDetailInfos == null) || (ordersInfo.OrderDetailInfos.Count <= 0))
                {
                    return ordersInfo;
                }
                Dictionary<string, PackInfo> packInfoList = new Dictionary<string, PackInfo>();
                for (int i = 0; i < ordersInfo.OrderDetailInfos.Count; i++)
                {
                    PackInfo packInfo = null;
                    if (packInfoList.ContainsKey(ordersInfo.OrderDetailInfos[i].PackID))
                    {
                        packInfo = packInfoList[ordersInfo.OrderDetailInfos[i].PackID];
                    }
                    else
                    {
                        packInfo = packDA.GetPackByID(ordersInfo.OrderDetailInfos[i].PackID, this.dataBaseID[0]);
                        packInfoList.Add(ordersInfo.OrderDetailInfos[i].PackID, packInfo);
                    }
                    ordersInfo.OrderDetailInfos[i].OriginalQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].OriginalQty, "R");
                    ordersInfo.OrderDetailInfos[i].OpenQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].OpenQty, "R");
                    ordersInfo.OrderDetailInfos[i].ShippedQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].ShippedQty, "R");
                    ordersInfo.OrderDetailInfos[i].AdjustedQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].AdjustedQty, "R");
                    ordersInfo.OrderDetailInfos[i].PreallocatedQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].PreallocatedQty, "R");
                    ordersInfo.OrderDetailInfos[i].AllocatedQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].AllocatedQty, "R");
                    ordersInfo.OrderDetailInfos[i].PickedQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].PickedQty, "R");
                }
            }
            return ordersInfo;
        }

        public OrdersInfo GetOrdersInfoByID(string ordersID)
        {
            OrdersInfo ordersInfo = ordersDA.GetOrdersByID(ordersID, this.dataBaseID[0], this.pubParasInfo);
            if (ordersInfo != null)
            {
                int i;
                PackInfo packInfo;
                ordersInfo.OrderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(ordersInfo.OrderID, this.dataBaseID[0], this.pubParasInfo);
                if (ordersInfo.OrderDetailInfos != null)
                {
                    Dictionary<string, SkuInfo> skuInfoList = new Dictionary<string, SkuInfo>();
                    Dictionary<string, List<LotAttributeInfo>> lotAttributeInfoList = new Dictionary<string, List<LotAttributeInfo>>();
                    foreach (OrderDetailInfo info in ordersInfo.OrderDetailInfos)
                    {
                        string strExpiryType = string.Empty;
                        SkuInfo skuInfo = null;
                        if (skuInfoList.ContainsKey(info.OwnerID + info.SkuID))
                        {
                            skuInfo = skuInfoList[info.OwnerID + info.SkuID];
                        }
                        else
                        {
                            skuInfo = skuDA.GetSkuByID(info.OwnerID, info.SkuID, this.dataBaseID[0]);
                            skuInfoList.Add(info.OwnerID + info.SkuID, skuInfo);
                        }
                        if ((skuInfo != null) && (skuInfo.ShelfLifeIndicator == "Y"))
                        {
                            DateTime dtExpiry;
                            DateTime dtExpiry1;
                            List<LotAttributeInfo> lotList = null;
                            if (lotAttributeInfoList.ContainsKey(info.OwnerID + info.SkuID))
                            {
                                lotList = lotAttributeInfoList[info.OwnerID + info.SkuID];
                            }
                            else
                            {
                                lotList = lotAttributeDA.GetInvLotAttributeByID(info.OwnerID, info.SkuID, this.dataBaseID[0]);
                                lotAttributeInfoList.Add(info.OwnerID + info.SkuID, lotList);
                            }
                            if (skuInfo.ShelfLifeCodeType.ToUpper() == "E")
                            {
                                if (skuInfo.ShelfLife > 0)
                                {
                                    dtExpiry = DateTime.Now;
                                    dtExpiry1 = DateTime.Now.AddDays(Convert.ToDouble(skuInfo.ShelfLife));
                                    DateTime dt = new DateTime();
                                    foreach (LotAttributeInfo lotInfo in lotList)
                                    {
                                        if (lotInfo.ExpiryDate != dt)
                                        {
                                            if ((dtExpiry <= lotInfo.ExpiryDate) && (dtExpiry1 >= lotInfo.ExpiryDate))
                                            {
                                                strExpiryType = "ABoutToExpire";
                                            }
                                            else if (dtExpiry > lotInfo.ExpiryDate)
                                            {
                                                strExpiryType = "Expired";
                                                goto Label_03A4;
                                            }
                                        }
                                    }
                                }
                            }
                            else if (skuInfo.ShelfLife > 0)
                            {
                                dtExpiry = DateTime.Now;
                                dtExpiry1 = DateTime.Now.AddDays(Convert.ToDouble(skuInfo.ShelfLife));
                                foreach (LotAttributeInfo lotInfo in lotList)
                                {
                                    if ((dtExpiry <= lotInfo.ProduceDate) && (dtExpiry1 >= lotInfo.ProduceDate))
                                    {
                                        strExpiryType = "ABoutToExpire";
                                    }
                                    else if (dtExpiry > lotInfo.ProduceDate)
                                    {
                                        strExpiryType = "Expired";
                                        goto Label_03A4;
                                    }
                                }
                            }
                        }
                    Label_03A4:
                        info.ExpiryType = strExpiryType;
                    }
                }
                ordersInfo.PreallocatePickDetailInfos = preallocatePickDetailDA.GetPreallocatePickDetailListByID(ordersInfo.OrderID, this.dataBaseID[0]);
                ordersInfo.PickDetailInfos = pickDetailDA.GetPickDetailByOrderID(ordersInfo.OrderID, this.dataBaseID[0], this.pubParasInfo);
                ordersInfo.ShippedDetailInfos = pickDetailDA.GetPickDetailByOrderID(ordersInfo.OrderID, " AND PD.STATUS = 'Shipped' ", this.dataBaseID[0], this.pubParasInfo);
                ordersInfo.ShipmentContainerInfos = shipmentContainerDA.GetShipmentContainerByOrderID(ordersInfo.OrderID, this.dataBaseID[0]);
                InboundHelper inboundHelper = new InboundHelper();
                OutboundMgtBLL outBoundMgtBll = new OutboundMgtBLL();
                Dictionary<string, PackInfo> packInfoList = new Dictionary<string, PackInfo>();
                if ((ordersInfo.OrderDetailInfos != null) && (ordersInfo.OrderDetailInfos.Count > 0))
                {
                    for (i = 0; i < ordersInfo.OrderDetailInfos.Count; i++)
                    {
                        packInfo = null;
                        if (packInfoList.ContainsKey(ordersInfo.OrderDetailInfos[i].PackID))
                        {
                            packInfo = packInfoList[ordersInfo.OrderDetailInfos[i].PackID];
                        }
                        else
                        {
                            packInfo = packDA.GetPackByID(ordersInfo.OrderDetailInfos[i].PackID, this.dataBaseID[0]);
                            packInfoList.Add(ordersInfo.OrderDetailInfos[i].PackID, packInfo);
                        }
                        ordersInfo.OrderDetailInfos[i].OriginalQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].OriginalQty, "R");
                        ordersInfo.OrderDetailInfos[i].OpenQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].OpenQty, "R");
                        ordersInfo.OrderDetailInfos[i].ShippedQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].ShippedQty, "R");
                        ordersInfo.OrderDetailInfos[i].AdjustedQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].AdjustedQty, "R");
                        ordersInfo.OrderDetailInfos[i].PreallocatedQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].PreallocatedQty, "R");
                        ordersInfo.OrderDetailInfos[i].AllocatedQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].AllocatedQty, "R");
                        ordersInfo.OrderDetailInfos[i].PickedQty = inboundHelper.ExchangeUom(packInfo, ordersInfo.OrderDetailInfos[i].UomID, ordersInfo.OrderDetailInfos[i].PickedQty, "R");
                    }
                }
                if ((ordersInfo.PickDetailInfos != null) && (ordersInfo.PickDetailInfos.Count > 0))
                {
                    for (i = 0; i < ordersInfo.PickDetailInfos.Count; i++)
                    {
                        packInfo = null;
                        if (packInfoList.ContainsKey(ordersInfo.PickDetailInfos[i].PackID))
                        {
                            packInfo = packInfoList[ordersInfo.PickDetailInfos[i].PackID];
                        }
                        else
                        {
                            packInfo = packDA.GetPackByID(ordersInfo.PickDetailInfos[i].PackID, this.dataBaseID[0]);
                            packInfoList.Add(ordersInfo.PickDetailInfos[i].PackID, packInfo);
                        }
                        ordersInfo.PickDetailInfos[i].Qty = inboundHelper.ExchangeUom(packInfo, ordersInfo.PickDetailInfos[i].UomID, ordersInfo.PickDetailInfos[i].Qty, "R");
                    }
                }
                if ((ordersInfo.PreallocatePickDetailInfos == null) || (ordersInfo.PreallocatePickDetailInfos.Count <= 0))
                {
                    return ordersInfo;
                }
                for (i = 0; i < ordersInfo.PreallocatePickDetailInfos.Count; i++)
                {
                    packInfo = null;
                    if (packInfoList.ContainsKey(ordersInfo.PreallocatePickDetailInfos[i].PackID))
                    {
                        packInfo = packInfoList[ordersInfo.PreallocatePickDetailInfos[i].PackID];
                    }
                    else
                    {
                        packInfo = packDA.GetPackByID(ordersInfo.PreallocatePickDetailInfos[i].PackID, this.dataBaseID[0]);
                        packInfoList.Add(ordersInfo.PreallocatePickDetailInfos[i].PackID, packInfo);
                    }
                    string uomID = outBoundMgtBll.ExchangeAllocateStratetyUom2PackUom(packInfo, ordersInfo.PreallocatePickDetailInfos[i].UomID);
                    ordersInfo.PreallocatePickDetailInfos[i].UomID = uomID;
                    ordersInfo.PreallocatePickDetailInfos[i].Qty = inboundHelper.ExchangeUom(packInfo, uomID, ordersInfo.PreallocatePickDetailInfos[i].Qty, "R");
                    ordersInfo.PreallocatePickDetailInfos[i].AllocatedQty = inboundHelper.ExchangeUom(packInfo, uomID, ordersInfo.PreallocatePickDetailInfos[i].AllocatedQty, "R");
                }
            }
            return ordersInfo;
        }

        public OrdersInfo GetOrdersInfoByQueryEntity(OrderDetailQueryEntity orderDetailQueryEntity)
        {
            OrdersInfo ordersInfo = ordersDA.GetOrdersByID(orderDetailQueryEntity.OrderID, this.dataBaseID[0], this.pubParasInfo);
            if (ordersInfo != null)
            {
                int i;
                PackInfo packInfo;
                ordersInfo.OrderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(orderDetailQueryEntity.OrderID, this.dataBaseID[0], this.pubParasInfo);
                if ((ordersInfo.OrderDetailInfos != null) && (ordersInfo.OrderDetailInfos.Count > 0))
                {
                    List<string> total = orderDetailDA.GetTotalQTYPriceByOrderID(orderDetailQueryEntity.OrderID, this.dataBaseID[0]);
                    ordersInfo.TotalOriginalQTY = decimal.Parse(total[0]);
                    ordersInfo.TotalPreAllocatedQTY = decimal.Parse(total[1]);
                    ordersInfo.TotalAllocatedQTY = decimal.Parse(total[2]);
                    ordersInfo.TotalPickedQTY = decimal.Parse(total[3]);
                    ordersInfo.TotalShippedQTY = decimal.Parse(total[4]);
                    ordersInfo.TotalExtendedPrice = decimal.Parse(total[5]);
                    ordersInfo.TotalCube = decimal.Parse(total[6]);
                    ordersInfo.TotalNetWgt = decimal.Parse(total[7]);
                    ordersInfo.TotalGrossWgt = decimal.Parse(total[8]);
                }
                List<string> strWhere = new List<string>();
                ordersInfo.DataSetOrderDetailInfo = orderDetailDA.GetOrderDetailByPagerQueryList(strWhere, orderDetailQueryEntity, this.dataBaseID[0], this.pubParasInfo);
                InboundHelper inboundHelper = new InboundHelper();
                OutboundMgtBLL outBoundMgtBll = new OutboundMgtBLL();
                Dictionary<string, PackInfo> packInfoList = new Dictionary<string, PackInfo>();
                if ((ordersInfo.DataSetOrderDetailInfo != null) && (ordersInfo.DataSetOrderDetailInfo.Tables.Count > 2))
                {
                    Dictionary<string, SkuInfo> skuInfoList = new Dictionary<string, SkuInfo>();
                    Dictionary<string, List<LotAttributeInfo>> lotAttributeInfoList = new Dictionary<string, List<LotAttributeInfo>> {  };
                    ordersInfo.DataSetOrderDetailInfo.Tables[1].Rows[0]["LINE_ID"] = commonMethod.GetMaxLineID("ORDER_DETAIL", orderDetailQueryEntity.OrderID, this.dataBaseID[0]);
                    for (i = 0; ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows.Count > i; i++)
                    {
                        string strExpiryType = string.Empty;
                        SkuInfo skuInfo = null;
                        if (skuInfoList.ContainsKey(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["OWNER_ID"].ToString() + ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["SKU_ID"].ToString()))
                        {
                            skuInfo = skuInfoList[ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["OWNER_ID"].ToString() + ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["SKU_ID"].ToString()];
                        }
                        else
                        {
                            skuInfo = skuDA.GetSkuByID(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["OWNER_ID"].ToString(), ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["SKU_ID"].ToString(), this.dataBaseID[0]);
                            skuInfoList.Add(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["OWNER_ID"].ToString() + ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["SKU_ID"].ToString(), skuInfo);
                        }
                        if ((skuInfo != null) && (skuInfo.ShelfLifeIndicator == "Y"))
                        {
                            DateTime dtExpiry;
                            DateTime dtExpiry1;
                            List<LotAttributeInfo> lotList = null;
                            if (lotAttributeInfoList.ContainsKey(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["OWNER_ID"].ToString() + ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["SKU_ID"].ToString()))
                            {
                                lotList = lotAttributeInfoList[ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["OWNER_ID"].ToString() + ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["SKU_ID"].ToString()];
                            }
                            else
                            {
                                lotList = lotAttributeDA.GetInvLotAttributeByID(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["OWNER_ID"].ToString(), ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["SKU_ID"].ToString(), this.dataBaseID[0]);
                                lotAttributeInfoList.Add(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["OWNER_ID"].ToString() + ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["SKU_ID"].ToString(), lotList);
                            }
                            if (skuInfo.ShelfLifeCodeType.ToUpper() == "E")
                            {
                                if (skuInfo.ShelfLife > 0)
                                {
                                    dtExpiry = DateTime.Now;
                                    dtExpiry1 = DateTime.Now.AddDays(Convert.ToDouble(skuInfo.ShelfLife));
                                    DateTime dt = new DateTime();
                                    foreach (LotAttributeInfo lotInfo in lotList)
                                    {
                                        if (lotInfo.ExpiryDate != dt)
                                        {
                                            if ((dtExpiry <= lotInfo.ExpiryDate) && (dtExpiry1 >= lotInfo.ExpiryDate))
                                            {
                                                strExpiryType = "ABoutToExpire";
                                            }
                                            else if (dtExpiry > lotInfo.ExpiryDate)
                                            {
                                                strExpiryType = "Expired";
                                                goto Label_07D9;
                                            }
                                        }
                                    }
                                }
                            }
                            else if (skuInfo.ShelfLife > 0)
                            {
                                dtExpiry = DateTime.Now;
                                dtExpiry1 = DateTime.Now.AddDays(Convert.ToDouble(skuInfo.ShelfLife));
                                foreach (LotAttributeInfo lotInfo in lotList)
                                {
                                    if ((dtExpiry <= lotInfo.ProduceDate) && (dtExpiry1 >= lotInfo.ProduceDate))
                                    {
                                        strExpiryType = "ABoutToExpire";
                                    }
                                    else if (dtExpiry > lotInfo.ProduceDate)
                                    {
                                        strExpiryType = "Expired";
                                        goto Label_07D9;
                                    }
                                }
                            }
                        }
                    Label_07D9:
                        ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["EXPIRY_TYPE"] = strExpiryType;
                        packInfo = null;
                        if (packInfoList.ContainsKey(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["PACK_ID"].ToString()))
                        {
                            packInfo = packInfoList[ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["PACK_ID"].ToString()];
                        }
                        else
                        {
                            packInfo = packDA.GetPackByID(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["PACK_ID"].ToString(), this.dataBaseID[0]);
                            packInfoList.Add(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["PACK_ID"].ToString(), packInfo);
                        }
                        ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["ORIGINAL_QTY"] = inboundHelper.ExchangeUom(packInfo, ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["UOM_ID"].ToString(), Convert.ToDecimal(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["ORIGINAL_QTY"]), "R");
                        ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["OPEN_QTY"] = inboundHelper.ExchangeUom(packInfo, ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["UOM_ID"].ToString(), Convert.ToDecimal(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["OPEN_QTY"]), "R");
                        ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["SHIPPED_QTY"] = inboundHelper.ExchangeUom(packInfo, ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["UOM_ID"].ToString(), Convert.ToDecimal(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["SHIPPED_QTY"]), "R");
                        ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["ADJUSTED_QTY"] = inboundHelper.ExchangeUom(packInfo, ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["UOM_ID"].ToString(), Convert.ToDecimal(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["ADJUSTED_QTY"]), "R");
                        ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["PREALLOCATED_QTY"] = inboundHelper.ExchangeUom(packInfo, ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["UOM_ID"].ToString(), Convert.ToDecimal(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["PREALLOCATED_QTY"]), "R");
                        ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["ALLOCATED_QTY"] = inboundHelper.ExchangeUom(packInfo, ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["UOM_ID"].ToString(), Convert.ToDecimal(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["ALLOCATED_QTY"]), "R");
                        ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["PICKED_QTY"] = inboundHelper.ExchangeUom(packInfo, ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["UOM_ID"].ToString(), Convert.ToDecimal(ordersInfo.DataSetOrderDetailInfo.Tables[2].Rows[i]["PICKED_QTY"]), "R");
                    }
                }
                ordersInfo.PreallocatePickDetailInfos = preallocatePickDetailDA.GetPreallocatePickDetailListByID(ordersInfo.OrderID, this.dataBaseID[0]);
                ordersInfo.PickDetailInfos = pickDetailDA.GetPickDetailByOrderID(ordersInfo.OrderID, this.dataBaseID[0], this.pubParasInfo);
                ordersInfo.ShippedDetailInfos = pickDetailDA.GetPickDetailByOrderID(ordersInfo.OrderID, " AND PD.STATUS = 'Shipped' ", this.dataBaseID[0], this.pubParasInfo);
                ordersInfo.ShipmentContainerInfos = shipmentContainerDA.GetShipmentContainerByOrderID(ordersInfo.OrderID, this.dataBaseID[0]);
                if ((ordersInfo.PickDetailInfos != null) && (ordersInfo.PickDetailInfos.Count > 0))
                {
                    for (i = 0; i < ordersInfo.PickDetailInfos.Count; i++)
                    {
                        packInfo = null;
                        if (packInfoList.ContainsKey(ordersInfo.PickDetailInfos[i].PackID))
                        {
                            packInfo = packInfoList[ordersInfo.PickDetailInfos[i].PackID];
                        }
                        else
                        {
                            packInfo = packDA.GetPackByID(ordersInfo.PickDetailInfos[i].PackID, this.dataBaseID[0]);
                            packInfoList.Add(ordersInfo.PickDetailInfos[i].PackID, packInfo);
                        }
                        ordersInfo.PickDetailInfos[i].Qty = inboundHelper.ExchangeUom(packInfo, ordersInfo.PickDetailInfos[i].UomID, ordersInfo.PickDetailInfos[i].Qty, "R");
                    }
                }
                if ((ordersInfo.PreallocatePickDetailInfos == null) || (ordersInfo.PreallocatePickDetailInfos.Count <= 0))
                {
                    return ordersInfo;
                }
                for (i = 0; i < ordersInfo.PreallocatePickDetailInfos.Count; i++)
                {
                    packInfo = null;
                    if (packInfoList.ContainsKey(ordersInfo.PreallocatePickDetailInfos[i].PackID))
                    {
                        packInfo = packInfoList[ordersInfo.PreallocatePickDetailInfos[i].PackID];
                    }
                    else
                    {
                        packInfo = packDA.GetPackByID(ordersInfo.PreallocatePickDetailInfos[i].PackID, this.dataBaseID[0]);
                        packInfoList.Add(ordersInfo.PreallocatePickDetailInfos[i].PackID, packInfo);
                    }
                    string uomID = outBoundMgtBll.ExchangeAllocateStratetyUom2PackUom(packInfo, ordersInfo.PreallocatePickDetailInfos[i].UomID);
                    ordersInfo.PreallocatePickDetailInfos[i].UomID = uomID;
                    ordersInfo.PreallocatePickDetailInfos[i].Qty = inboundHelper.ExchangeUom(packInfo, uomID, ordersInfo.PreallocatePickDetailInfos[i].Qty, "R");
                    ordersInfo.PreallocatePickDetailInfos[i].AllocatedQty = inboundHelper.ExchangeUom(packInfo, uomID, ordersInfo.PreallocatePickDetailInfos[i].AllocatedQty, "R");
                }
            }
            return ordersInfo;
        }

        public string GetOrderStatus(List<OrderDetailInfo> orderDetailInfos)
        {
            string status = OrderStatus.New;
            if ((orderDetailInfos != null) && (orderDetailInfos.Count > 0))
            {
                int totalCount = orderDetailInfos.Count;
                int New = 0;
                int PartPreAllocated = 0;
                int PreAllocated = 0;
                int PartAllocated = 0;
                int Allocated = 0;
                int PartPicked = 0;
                int Picked = 0;
                int PartShipped = 0;
                int Shipped = 0;
                for (int i = 0; i < orderDetailInfos.Count; i++)
                {
                    string tmpStatus = orderDetailInfos[i].Status.ToUpper();
                    if (tmpStatus == OrderStatus.New.ToUpper())
                    {
                        New++;
                    }
                    if (tmpStatus == OrderStatus.PartPreAllocated.ToUpper())
                    {
                        PartPreAllocated++;
                    }
                    if (tmpStatus == OrderStatus.PreAllocated.ToUpper())
                    {
                        PreAllocated++;
                    }
                    if (tmpStatus == OrderStatus.PartAllocated.ToUpper())
                    {
                        PartAllocated++;
                    }
                    if (tmpStatus == OrderStatus.Allocated.ToUpper())
                    {
                        Allocated++;
                    }
                    if (tmpStatus == OrderStatus.PartPicked.ToUpper())
                    {
                        PartPicked++;
                    }
                    if (tmpStatus == OrderStatus.Picked.ToUpper())
                    {
                        Picked++;
                    }
                    if (tmpStatus == OrderStatus.PartShipped.ToUpper())
                    {
                        PartShipped++;
                    }
                    if (tmpStatus == OrderStatus.Shipped.ToUpper())
                    {
                        Shipped++;
                    }
                }
                if (New == 0)
                {
                    status = OrderStatus.New;
                }
                if (PartPreAllocated > 0)
                {
                    status = OrderStatus.PartPreAllocated;
                }
                if ((PreAllocated > 0) && (PreAllocated < totalCount))
                {
                    status = OrderStatus.PartPreAllocated;
                }
                if (PreAllocated == totalCount)
                {
                    status = OrderStatus.PreAllocated;
                }
                if (PartAllocated > 0)
                {
                    status = OrderStatus.PartAllocated;
                }
                if ((Allocated > 0) && (Allocated < totalCount))
                {
                    status = OrderStatus.PartAllocated;
                }
                if (Allocated == totalCount)
                {
                    status = OrderStatus.Allocated;
                }
                if (PartPicked > 0)
                {
                    status = OrderStatus.PartPicked;
                }
                if ((Picked > 0) && (Picked < totalCount))
                {
                    status = OrderStatus.PartPicked;
                }
                if (Picked == totalCount)
                {
                    status = OrderStatus.Picked;
                }
                if (PartShipped > 0)
                {
                    status = OrderStatus.PartShipped;
                }
                if ((Shipped > 0) && (Shipped < totalCount))
                {
                    status = OrderStatus.PartShipped;
                }
                if (Shipped == totalCount)
                {
                    status = OrderStatus.Shipped;
                }
            }
            return status;
        }

        public string GetOrderStatus(string orderID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string status = OrderStatus.New;
            DataSet ds = ordersDA.GetOrderStatusByOrderDetailStatus(orderID, whLoginID);
            if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
            {
                int totalCount = ds.Tables[0].Rows.Count;
                int New = 0;
                int PartPreAllocated = 0;
                int PreAllocated = 0;
                int PartAllocated = 0;
                int Allocated = 0;
                int PartPicked = 0;
                int Picked = 0;
                int PartShipped = 0;
                int Shipped = 0;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string tmpStatus = ds.Tables[0].Rows[i]["STATUS"].ToString().ToUpper();
                    if (tmpStatus == OrderStatus.New.ToUpper())
                    {
                        New++;
                    }
                    if (tmpStatus == OrderStatus.PartPreAllocated.ToUpper())
                    {
                        PartPreAllocated++;
                    }
                    if (tmpStatus == OrderStatus.PreAllocated.ToUpper())
                    {
                        PreAllocated++;
                    }
                    if (tmpStatus == OrderStatus.PartAllocated.ToUpper())
                    {
                        PartAllocated++;
                    }
                    if (tmpStatus == OrderStatus.Allocated.ToUpper())
                    {
                        Allocated++;
                    }
                    if (tmpStatus == OrderStatus.PartPicked.ToUpper())
                    {
                        PartPicked++;
                    }
                    if (tmpStatus == OrderStatus.Picked.ToUpper())
                    {
                        Picked++;
                    }
                    if (tmpStatus == OrderStatus.PartShipped.ToUpper())
                    {
                        PartShipped++;
                    }
                    if (tmpStatus == OrderStatus.Shipped.ToUpper())
                    {
                        Shipped++;
                    }
                }
                if (New == 0)
                {
                    status = OrderStatus.New;
                }
                if (PartPreAllocated > 0)
                {
                    status = OrderStatus.PartPreAllocated;
                }
                if ((PreAllocated > 0) && (PreAllocated < totalCount))
                {
                    status = OrderStatus.PartPreAllocated;
                }
                if (PreAllocated == totalCount)
                {
                    status = OrderStatus.PreAllocated;
                }
                if (PartAllocated > 0)
                {
                    status = OrderStatus.PartAllocated;
                }
                if ((Allocated > 0) && (Allocated < totalCount))
                {
                    status = OrderStatus.PartAllocated;
                }
                if (Allocated == totalCount)
                {
                    status = OrderStatus.Allocated;
                }
                if (PartPicked > 0)
                {
                    status = OrderStatus.PartPicked;
                }
                if ((Picked > 0) && (Picked < totalCount))
                {
                    status = OrderStatus.PartPicked;
                }
                if (Picked == totalCount)
                {
                    status = OrderStatus.Picked;
                }
                if (PartShipped > 0)
                {
                    status = OrderStatus.PartShipped;
                }
                if ((Shipped > 0) && (Shipped < totalCount))
                {
                    status = OrderStatus.PartShipped;
                }
                if (Shipped == totalCount)
                {
                    status = OrderStatus.Shipped;
                }
            }
            return status;
        }

        public string GetOrderStatus(DataBase dataBase, DbTransaction tran, string orderID, string whLoginID, PubParasInfo pubParasInfo)
        {
            List<OrderDetailInfo> orderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(dataBase, tran, orderID, whLoginID, pubParasInfo);
            return this.GetOrderStatus(orderDetailInfos);
        }

        public List<OrdersInfo> GetShippingReviewByOrderID(string orderID, string ShippingReviewType)
        {
            List<OrdersInfo> orderList = new List<OrdersInfo>();
            if (ShippingReviewType == "ShippingOrder")
            {
                OrdersInfo orderinfo = ordersDA.GetShippingReviewByOrderID(orderID, this.dataBaseID[0], this.pubParasInfo);
                if (orderinfo != null)
                {
                    if (orderinfo.Status.ToUpper() != "PICKED")
                    {
                        throw new Exception("发货单" + orderID + "状态不等于拣货完成,无法进行复核!");
                    }
                    orderinfo.OrderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(orderID, this.dataBaseID[0], this.pubParasInfo);
                    orderList.Add(orderinfo);
                }
                return orderList;
            }
            orderList = waveDetailDA.GetOrdersInfoByWaveID(orderID, this.dataBaseID[0], this.pubParasInfo);
            foreach (OrdersInfo info in orderList)
            {
                if (info.Status.ToUpper() != "PICKED")
                {
                    throw new Exception("发货单" + orderID + "状态不等于拣货完成,无法进行复核!");
                }
                info.OrderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(info.OrderID, this.dataBaseID[0], this.pubParasInfo);
            }
            return orderList;
        }

        public OrdersInfo GetShippingWeightByOrderID(string orderID)
        {
            return ordersDA.GetShippingWeightByOrderID(orderID, this.dataBaseID[0], this.pubParasInfo);
        }

        public string ImportByDataSet(DataSet ds)
        {
            string ImportFalse = string.Empty;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            string PreExternOrderID = string.Empty;
            string PreSavedExternOrderID = string.Empty;
            int lineID = 10;
            OrdersInfo ordersInfo = new OrdersInfo();
            List<OrderDetailInfo> orderDetailInfoList = new List<OrderDetailInfo>();
            try
            {
                int j;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DateTime CS00003;
                    OrderDetailInfo orderDetailInfo = new OrderDetailInfo();
                    if (string.Compare(PreExternOrderID, ds.Tables[0].Rows[i][1].ToString().Trim(), true) != 0)
                    {
                        if (((string.IsNullOrEmpty(ImportFalse) && (ordersInfo != null)) && (!string.IsNullOrEmpty(ordersInfo.ExternOrderID) && (ordersInfo.OrderDetailInfos != null))) && (ordersInfo.OrderDetailInfos.Count > 0))
                        {
                            if (!ownerDA.CheckTradePartnerIDUnique(dataBase, tran, ordersInfo.OwnerID, this.dataBaseID[0]))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F7100_003", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.OwnerID });
                            }
                            else if (!commonMethod.CheckAuthorizationOwnerByUserID(dataBase, tran, this.pubParasInfo.UserID, ordersInfo.OwnerID))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F7100_004", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.OwnerID });
                            }
                            if (!string.IsNullOrEmpty(ordersInfo.CarrierID))
                            {
                                if (!carrierDA.CheckCarrierIDUnique(dataBase, tran, ordersInfo.CarrierID, this.dataBaseID[0]))
                                {
                                    PublicMethod.GetInstance().ShowAlertMessage("F2140_001", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.CarrierID });
                                }
                                else if (!carrierDA.CheckAuthorizationCarrierUserID(dataBase, tran, ordersInfo.CarrierID, this.dataBaseID[0], this.pubParasInfo))
                                {
                                    PublicMethod.GetInstance().ShowAlertMessage("F2140_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.CarrierID });
                                }
                            }
                            if (!string.IsNullOrEmpty(ordersInfo.DestinationPort) && !portDA.CheckPortIDUnique(dataBase, tran, ordersInfo.DestinationPort, this.dataBaseID[0]))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F2140_004", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.DestinationPort });
                            }
                            if (!string.IsNullOrEmpty(ordersInfo.DeparturePort) && !portDA.CheckPortIDUnique(dataBase, tran, ordersInfo.DeparturePort, this.dataBaseID[0]))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F2140_005", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.DeparturePort });
                            }
                            if (!string.IsNullOrEmpty(ordersInfo.ConsigneeID))
                            {
                                if (string.Compare(ordersInfo.Type, "Return", true) == 0)
                                {
                                    if (!vendorDA.CheckVendorIDUnique(dataBase, tran, ordersInfo.ConsigneeID, this.dataBaseID[0]))
                                    {
                                        PublicMethod.GetInstance().ShowAlertMessage("F4200_006", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                                    }
                                    else if (!vendorDA.CheckAuthorizationVendorIDUserID(dataBase, tran, ordersInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                                    {
                                        PublicMethod.GetInstance().ShowAlertMessage("F2130_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                                    }
                                }
                                else if (!customerDA.CheckCustomerIDUnique(dataBase, tran, ordersInfo.ConsigneeID, this.dataBaseID[0]))
                                {
                                    PublicMethod.GetInstance().ShowAlertMessage("F2120_001", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                                }
                                else if (!customerDA.CheckAuthorizationCustomerIDUserID(dataBase, tran, ordersInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                                {
                                    PublicMethod.GetInstance().ShowAlertMessage("F2120_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                                }
                            }
                            if (!string.IsNullOrEmpty(ordersInfo.BillToID))
                            {
                                if (!billingEntityDA.CheckBillingEntityIDUnique(dataBase, tran, ordersInfo.BillToID, this.dataBaseID[0]))
                                {
                                    PublicMethod.GetInstance().ShowAlertMessage("F2150_001", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.BillToID });
                                }
                                else if (!billingEntityDA.CheckAuthorizationBillingEntityUserID(dataBase, tran, ordersInfo.BillToID, this.pubParasInfo, this.dataBaseID[0]))
                                {
                                    PublicMethod.GetInstance().ShowAlertMessage("F2150_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.BillToID });
                                }
                            }
                            if (!string.IsNullOrEmpty(ordersInfo.OrderID))
                            {
                                if (ordersDA.CheckOrdersIDUnique(dataBase, tran, ordersInfo.OrderID, this.dataBaseID[0]))
                                {
                                    PublicMethod.GetInstance().ShowAlertMessage("F7100_005", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.OrderID });
                                }
                            }
                            else
                            {
                                ordersInfo.OrderID = commonMethod.GenNextNumStr(dataBase, tran, "ORDERS", this.dataBaseID[0]);
                            }
                            if (string.IsNullOrEmpty(ImportFalse) && (ordersDA.InsertOrders(dataBase, tran, ordersInfo, this.dataBaseID[0]) > 0))
                            {
                                auditDataBLL.InsertAuditData<OrdersInfo>(dataBase, tran, null, ordersInfo, AuditAction.Insert, this.pubParasInfo.UserID, "ORDERS", this.dataBaseID[0]);
                            }
                            if ((string.IsNullOrEmpty(ImportFalse) && (ordersInfo.OrderDetailInfos != null)) && (ordersInfo.OrderDetailInfos.Count > 0))
                            {
                                j = 0;
                                while (j < ordersInfo.OrderDetailInfos.Count)
                                {
                                    ordersInfo.OrderDetailInfos[j].OrderID = ordersInfo.OrderID;
                                    if (orderDetailDA.CheckOrderDetailIDUnique(dataBase, tran, ordersInfo.OrderDetailInfos[j].OrderID, ordersInfo.OrderDetailInfos[j].LineID.ToString(), this.dataBaseID[0]))
                                    {
                                        PublicMethod.GetInstance().ShowAlertMessage("F7100_006", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.OrderDetailInfos[j].OrderID, ordersInfo.OrderDetailInfos[j].LineID.ToString() });
                                    }
                                    else
                                    {
                                        ordersInfo.OrderDetailInfos[j].CreatedDate = DateTime.Now;
                                        ordersInfo.OrderDetailInfos[j].UpdatedDate = DateTime.Now;
                                        ordersInfo.OrderDetailInfos[j].CreatedBy = this.pubParasInfo.UserID;
                                        ordersInfo.OrderDetailInfos[j].UpdatedBy = this.pubParasInfo.UserID;
                                        orderDetailDA.InsertOrderDetail(dataBase, tran, ordersInfo.OrderDetailInfos[j], this.dataBaseID[0]);
                                        auditDataBLL.InsertAuditData<OrderDetailInfo>(dataBase, tran, null, ordersInfo.OrderDetailInfos[j], AuditAction.Insert, this.pubParasInfo.UserID, "ORDER_DETAIL", this.dataBaseID[0]);
                                    }
                                    j++;
                                }
                            }
                            PreSavedExternOrderID = ordersInfo.ExternOrderID;
                        }
                        ordersInfo = new OrdersInfo {
                            OrderID = "",
                            OwnerID = ds.Tables[0].Rows[i][0].ToString().Trim(),
                            ExternOrderID = ds.Tables[0].Rows[i][1].ToString().Trim(),
                            OrderDate = (ds.Tables[0].Rows[i][2].ToString().Trim() == "") ? DateTime.Today : DateTime.Parse(ds.Tables[0].Rows[i][2].ToString().Trim()),
                            ConsigneeID = ds.Tables[0].Rows[i][3].ToString().Trim(),
                            Remark = ds.Tables[0].Rows[i][4].ToString().Trim(),
                            CCompany = ds.Tables[0].Rows[i][12].ToString().Trim(),
                            CCity = ds.Tables[0].Rows[i][13].ToString().Trim(),
                            CProv = ds.Tables[0].Rows[i][14].ToString().Trim(),
                            CZip = ds.Tables[0].Rows[i][15].ToString().Trim(),
                            CCountry = ds.Tables[0].Rows[i][0x10].ToString().Trim(),
                            CAddress = ds.Tables[0].Rows[i][0x11].ToString().Trim(),
                            CContact1 = ds.Tables[0].Rows[i][0x12].ToString().Trim(),
                            CPhone1 = ds.Tables[0].Rows[i][0x13].ToString().Trim(),
                            CoreReleaseID = "",
                            IsDeclartion = "N",
                            CreatedBy = this.pubParasInfo.UserID,
                            UpdatedBy = this.pubParasInfo.UserID,
                            Status = "New",
                            Type = "Standard",
                            IsActive = "Y",
                            DeliveryDate = DateTime.Now,
                            DepartureDate = DateTime.Now,
                            Priority = "5",
                            OrderGroup = "",
                            BillToID = "",
                            Door = "",
                            Route = "",
                            Stop = "",
                            Stage = "",
                            BatchFlag = "N",
                            ShipTogether = "N",
                            OrderValue = 0M,
                            UpdateSource = "0",
                            IntransitID = "",
                            CreatedDate = DateTime.Now,
                            UpdatedDate = DateTime.Now
                        };
                        PreExternOrderID = ds.Tables[0].Rows[i][1].ToString().Trim();
                        lineID = 10;
                        orderDetailInfoList.Clear();
                        if (!ownerDA.CheckTradePartnerIDUnique(dataBase, tran, ordersInfo.OwnerID, this.dataBaseID[0]))
                        {
                            ImportFalse = ImportFalse + string.Format("第{0}行货主{1}不存在!<br />", i + 1, ordersInfo.OwnerID);
                        }
                        if (!string.IsNullOrEmpty(ordersInfo.ConsigneeID) && !customerDA.CheckCustomerIDUnique(dataBase, tran, ordersInfo.ConsigneeID, this.dataBaseID[0]))
                        {
                            ImportFalse = ImportFalse + string.Format("第{0}行客户{1}不存在!<br />", i + 1, ordersInfo.ConsigneeID);
                        }
                    }
                    orderDetailInfo.LineID = lineID;
                    orderDetailInfo.ExternOrderID = ds.Tables[0].Rows[i][1].ToString().Trim();
                    orderDetailInfo.OwnerID = ds.Tables[0].Rows[i][0].ToString().Trim();
                    orderDetailInfo.SkuID = ds.Tables[0].Rows[i][5].ToString().Trim();
                    orderDetailInfo.OriginalQty = (ds.Tables[0].Rows[i][6].ToString().Trim() == "") ? 0M : decimal.Parse(ds.Tables[0].Rows[i][6].ToString().Trim());
                    orderDetailInfo.LotAttr09 = ds.Tables[0].Rows[i][7].ToString().Trim().ToUpper();
                    orderDetailInfo.VendorID = ds.Tables[0].Rows[i][8].ToString().Trim();
                    orderDetailInfo.ExternalLot = ds.Tables[0].Rows[i][9].ToString().Trim();
                    orderDetailInfo.ProduceDate = string.IsNullOrEmpty(ds.Tables[0].Rows[i][10].ToString().Trim()) ? (CS00003 = new DateTime()) : DateTime.Parse(ds.Tables[0].Rows[i][10].ToString().Trim());
                    orderDetailInfo.ExpiryDate = string.IsNullOrEmpty(ds.Tables[0].Rows[i][11].ToString().Trim()) ? (CS00003 = new DateTime()) : DateTime.Parse(ds.Tables[0].Rows[i][11].ToString().Trim());
                    orderDetailInfo.LotAttr01 = ds.Tables[0].Rows[i][20].ToString().Trim();
                    orderDetailInfo.LotAttr02 = ds.Tables[0].Rows[i][0x15].ToString().Trim();
                    orderDetailInfo.LotAttr03 = ds.Tables[0].Rows[i][0x16].ToString().Trim();
                    orderDetailInfo.LotAttr04 = ds.Tables[0].Rows[i][0x17].ToString().Trim();
                    orderDetailInfo.LotAttr05 = ds.Tables[0].Rows[i][0x18].ToString().Trim();
                    orderDetailInfo.LotAttr06 = ds.Tables[0].Rows[i][0x19].ToString().Trim();
                    orderDetailInfo.LotAttr07 = ds.Tables[0].Rows[i][0x1a].ToString().Trim();
                    orderDetailInfo.LotAttr08 = ds.Tables[0].Rows[i][0x1b].ToString().Trim();
                    orderDetailInfo.LotAttr10 = "";
                    orderDetailInfo.ExternLineID = "";
                    orderDetailInfo.AltSkuID = "";
                    orderDetailInfo.OpenQty = 0M;
                    orderDetailInfo.ShippedQty = 0M;
                    orderDetailInfo.AdjustedQty = 0M;
                    orderDetailInfo.PreallocatedQty = 0M;
                    orderDetailInfo.AllocatedQty = 0M;
                    orderDetailInfo.PickedQty = 0M;
                    orderDetailInfo.PickCode = "";
                    orderDetailInfo.LpnID = "";
                    orderDetailInfo.Status = "New";
                    orderDetailInfo.Tax01 = 0.0;
                    orderDetailInfo.Tax02 = 0.0;
                    orderDetailInfo.UnitPrice = 0.0;
                    orderDetailInfo.ExtendedPrice = 0.0;
                    orderDetailInfo.UpdateSource = "0";
                    orderDetailInfo.QcRequired = "0";
                    orderDetailInfo.QcAutoAdjust = "0";
                    orderDetailInfo.ShipGroup01 = "N";
                    orderDetailInfo.ShipGroup02 = "N";
                    orderDetailInfo.ShipGroup03 = "N";
                    orderDetailInfo.IsSubstitute = 0;
                    orderDetailInfo.OkToSubstitute = 0;
                    orderDetailInfo.Lot = "";
                    orderDetailInfo.EffectiveDate = DateTime.Now;
                    orderDetailInfo.OrigCaseQty = 0M;
                    orderDetailInfo.OrigPalletQty = 0M;
                    orderDetailInfo.QtyIntransit = 0M;
                    orderDetailInfo.WpReleased = "0";
                    orderDetailInfo.MinShipperCent = 0;
                    orderDetailInfo.PreallocateRuleID = "STD";
                    orderDetailInfo.AllocateRuleID = "STD";
                    orderDetailInfo.SkuRotation = "STD";
                    SkuInfo skuInfo = skuDA.GetSkuByID(orderDetailInfo.OwnerID, orderDetailInfo.SkuID, this.dataBaseID[0]);
                    if (skuInfo != null)
                    {
                        if (skuInfo.IsActive != "Y")
                        {
                            throw new Exception(orderDetailInfo.SkuID + "( 货主" + orderDetailInfo.OwnerID + "  Sku(货品 " + orderDetailInfo.SkuID + ")未启用,导入失败");
                        }
                        PackInfo packInfo = packDA.GetPackByID(skuInfo.PackID, this.dataBaseID[0]);
                        orderDetailInfo.SkuDescr = skuInfo.Descr;
                        orderDetailInfo.PackID = skuInfo.PackID;
                        orderDetailInfo.UomID = packInfo.PackUom1;
                        orderDetailInfo.PreallocateRuleID = skuInfo.PreallocateRuleID;
                        orderDetailInfo.AllocateRuleID = skuInfo.AllocateRuleID;
                        orderDetailInfo.SkuRotation = skuInfo.RotationRuleID;
                        orderDetailInfo.CartonGroup = skuInfo.CartonGroup;
                        orderDetailInfo.ProductWeight = skuInfo.GrossWgt * double.Parse(orderDetailInfo.OriginalQty.ToString());
                        orderDetailInfo.ProductCube = skuInfo.Cube * double.Parse(orderDetailInfo.OriginalQty.ToString());
                        if (!string.IsNullOrEmpty(skuInfo.PreallocateRuleID))
                        {
                            orderDetailInfo.PreallocateRuleID = skuInfo.PreallocateRuleID;
                        }
                        if (!string.IsNullOrEmpty(skuInfo.AllocateRuleID))
                        {
                            orderDetailInfo.AllocateRuleID = skuInfo.AllocateRuleID;
                        }
                        if (!string.IsNullOrEmpty(skuInfo.RotationRuleID))
                        {
                            orderDetailInfo.SkuRotation = skuInfo.RotationRuleID;
                        }
                    }
                    else
                    {
                        ImportFalse = ImportFalse + string.Format("第{0}行货品{1}不存在!<br />", i + 1, orderDetailInfo.SkuID);
                    }
                    orderDetailInfo.CreatedBy = this.pubParasInfo.UserID;
                    orderDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                    orderDetailInfoList.Add(orderDetailInfo);
                    ordersInfo.OrderDetailInfos = orderDetailInfoList;
                    lineID += 10;
                }
                if ((((string.IsNullOrEmpty(ImportFalse) && (ordersInfo != null)) && (!string.IsNullOrEmpty(ordersInfo.ExternOrderID) && (ordersInfo.OrderDetailInfos != null))) && (ordersInfo.OrderDetailInfos.Count > 0)) && (PreSavedExternOrderID != ordersInfo.ExternOrderID))
                {
                    if (!ownerDA.CheckTradePartnerIDUnique(dataBase, tran, ordersInfo.OwnerID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F7100_003", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.OwnerID });
                    }
                    else if (!commonMethod.CheckAuthorizationOwnerByUserID(dataBase, tran, this.pubParasInfo.UserID, ordersInfo.OwnerID))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F7100_004", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.OwnerID });
                    }
                    if (!string.IsNullOrEmpty(ordersInfo.CarrierID))
                    {
                        if (!carrierDA.CheckCarrierIDUnique(dataBase, tran, ordersInfo.CarrierID, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2140_001", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.CarrierID });
                        }
                        else if (!carrierDA.CheckAuthorizationCarrierUserID(dataBase, tran, ordersInfo.CarrierID, this.dataBaseID[0], this.pubParasInfo))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2140_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.CarrierID });
                        }
                    }
                    if (!string.IsNullOrEmpty(ordersInfo.DestinationPort) && !portDA.CheckPortIDUnique(dataBase, tran, ordersInfo.DestinationPort, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_004", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.DestinationPort });
                    }
                    if (!string.IsNullOrEmpty(ordersInfo.DeparturePort) && !portDA.CheckPortIDUnique(dataBase, tran, ordersInfo.DeparturePort, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_005", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.DeparturePort });
                    }
                    if (!string.IsNullOrEmpty(ordersInfo.ConsigneeID))
                    {
                        if (string.Compare(ordersInfo.Type, "Return", true) == 0)
                        {
                            if (!vendorDA.CheckVendorIDUnique(dataBase, tran, ordersInfo.ConsigneeID, this.dataBaseID[0]))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F4200_006", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                            }
                            else if (!vendorDA.CheckAuthorizationVendorIDUserID(dataBase, tran, ordersInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F2130_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                            }
                        }
                        else if (!customerDA.CheckCustomerIDUnique(dataBase, tran, ordersInfo.ConsigneeID, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2120_001", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                        }
                        else if (!customerDA.CheckAuthorizationCustomerIDUserID(dataBase, tran, ordersInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2120_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                        }
                    }
                    if (!string.IsNullOrEmpty(ordersInfo.BillToID))
                    {
                        if (!billingEntityDA.CheckBillingEntityIDUnique(dataBase, tran, ordersInfo.BillToID, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2150_001", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.BillToID });
                        }
                        else if (!billingEntityDA.CheckAuthorizationBillingEntityUserID(dataBase, tran, ordersInfo.BillToID, this.pubParasInfo, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2150_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.BillToID });
                        }
                    }
                    if (!string.IsNullOrEmpty(ordersInfo.OrderID))
                    {
                        if (ordersDA.CheckOrdersIDUnique(dataBase, tran, ordersInfo.OrderID, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F7100_005", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.OrderID });
                        }
                    }
                    else
                    {
                        ordersInfo.OrderID = commonMethod.GenNextNumStr(dataBase, tran, "ORDERS", this.dataBaseID[0]);
                    }
                    if (string.IsNullOrEmpty(ImportFalse) && (ordersDA.InsertOrders(dataBase, tran, ordersInfo, this.dataBaseID[0]) > 0))
                    {
                        auditDataBLL.InsertAuditData<OrdersInfo>(dataBase, tran, null, ordersInfo, AuditAction.Insert, this.pubParasInfo.UserID, "ORDERS", this.dataBaseID[0]);
                    }
                    if ((string.IsNullOrEmpty(ImportFalse) && (ordersInfo.OrderDetailInfos != null)) && (ordersInfo.OrderDetailInfos.Count > 0))
                    {
                        for (j = 0; j < ordersInfo.OrderDetailInfos.Count; j++)
                        {
                            ordersInfo.OrderDetailInfos[j].OrderID = ordersInfo.OrderID;
                            if (orderDetailDA.CheckOrderDetailIDUnique(dataBase, tran, ordersInfo.OrderDetailInfos[j].OrderID, ordersInfo.OrderDetailInfos[j].LineID.ToString(), this.dataBaseID[0]))
                            {
                                PublicMethod.GetInstance().ShowAlertMessage("F7100_006", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.OrderDetailInfos[j].OrderID, ordersInfo.OrderDetailInfos[j].LineID.ToString() });
                            }
                            else
                            {
                                ordersInfo.OrderDetailInfos[j].CreatedDate = DateTime.Now;
                                ordersInfo.OrderDetailInfos[j].UpdatedDate = DateTime.Now;
                                ordersInfo.OrderDetailInfos[j].CreatedBy = this.pubParasInfo.UserID;
                                ordersInfo.OrderDetailInfos[j].UpdatedBy = this.pubParasInfo.UserID;
                                orderDetailDA.InsertOrderDetail(dataBase, tran, ordersInfo.OrderDetailInfos[j], this.dataBaseID[0]);
                                auditDataBLL.InsertAuditData<OrderDetailInfo>(dataBase, tran, null, ordersInfo.OrderDetailInfos[j], AuditAction.Insert, this.pubParasInfo.UserID, "ORDER_DETAIL", this.dataBaseID[0]);
                            }
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                ImportFalse = ImportFalse + ex.Message;
            }
            finally
            {
                conn.Close();
            }
            return ImportFalse;
        }

        public string InsertOrders(OrdersInfo ordersInfo)
        {
            PortInfo destPort;
            IOwnerDA ownerDA = DataAccess.CreateOwnerDA();
            if (!ownerDA.CheckTradePartnerIDUnique(ordersInfo.OwnerID, this.dataBaseID[0]))
            {
                PublicMethod.GetInstance().ShowAlertMessage("F7100_003", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.OwnerID });
            }
            else if (!commonMethod.CheckAuthorizationOwnerByUserID(this.pubParasInfo.UserID, ordersInfo.OwnerID))
            {
                PublicMethod.GetInstance().ShowAlertMessage("F7100_004", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.OwnerID });
            }
            if (!string.IsNullOrEmpty(ordersInfo.DestinationPort))
            {
                destPort = portDA.GetPortByID(ordersInfo.DestinationPort, this.dataBaseID[0]);
                if ((destPort == null) || (destPort.IsActive == "N"))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2140_004", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.DestinationPort });
                }
            }
            if (!string.IsNullOrEmpty(ordersInfo.DeparturePort))
            {
                destPort = portDA.GetPortByID(ordersInfo.DeparturePort, this.dataBaseID[0]);
                if ((destPort == null) || (destPort.IsActive == "N"))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2140_005", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.DeparturePort });
                }
            }
            if (!string.IsNullOrEmpty(ordersInfo.CarrierID))
            {
                if (!carrierDA.CheckCarrierIDUnique(ordersInfo.CarrierID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2140_001", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.CarrierID });
                }
                else if (!carrierDA.CheckAuthorizationCarrierUserID(ordersInfo.CarrierID, this.dataBaseID[0], this.pubParasInfo))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2140_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.CarrierID });
                }
            }
            if (!string.IsNullOrEmpty(ordersInfo.ConsigneeID))
            {
                if (string.Compare(ordersInfo.Type, "Return", true) == 0)
                {
                    if (!vendorDA.CheckVendorIDUnique(ordersInfo.ConsigneeID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F4200_006", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                    }
                    else if (!vendorDA.CheckAuthorizationVendorIDUserID(ordersInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2130_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                    }
                }
                else if (ordersInfo.Type != OrderTypes.Transfer)
                {
                    if (!customerDA.CheckCustomerIDUnique(ordersInfo.ConsigneeID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_001", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                    }
                    else if (!customerDA.CheckAuthorizationCustomerIDUserID(ordersInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2120_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                    }
                }
            }
            if (!string.IsNullOrEmpty(ordersInfo.BillToID))
            {
                if (!billingEntityDA.CheckBillingEntityIDUnique(ordersInfo.BillToID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2150_001", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.BillToID });
                }
                else if (!billingEntityDA.CheckAuthorizationBillingEntityUserID(ordersInfo.BillToID, this.pubParasInfo, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2150_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.BillToID });
                }
            }
            if (!string.IsNullOrEmpty(ordersInfo.OrderID))
            {
                if (ordersDA.CheckOrdersIDUnique(ordersInfo.OrderID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F7100_005", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.OrderID });
                }
            }
            else
            {
                ordersInfo.OrderID = commonMethod.GenNextNumStr("ORDERS", this.dataBaseID[0]);
            }
            TradePartnerInfo tradePartnerInfo = ownerDA.GetTradePartnerByID(ordersInfo.OwnerID, this.dataBaseID[0]);
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string ordersID = string.Empty;
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            try
            {
                int i;
                string IntransitID = string.Empty;
                if (ordersInfo.Type.ToUpper() == "TRANSFER")
                {
                    IntransitID = commonMethod.GenNextNumStr(dataBase, tran, "INTRANSIT", this.dataBaseID[0]);
                    IntransitInfo intransitInfo = new IntransitInfo {
                        IntransitID = IntransitID,
                        SrcWhDbID = int.Parse(this.currentWhName),
                        DestWhDbID = int.Parse(ordersInfo.DestWhDbID),
                        OwnerID = ordersInfo.OwnerID,
                        OrderID = ordersInfo.OrderID,
                        ReceiptID = "",
                        OrderDate = ordersInfo.OrderDate,
                        Status = "New",
                        ActualShipDate = ordersInfo.ActualShipDate,
                        ExpectedReceiptDate = ordersInfo.DeliveryDate,
                        IsActive = "Y",
                        CreatedBy = ordersInfo.CreatedBy,
                        UpdatedBy = ordersInfo.UpdatedBy,
                        CreatedDate = DateTime.Now,
                        UpdatedDate = DateTime.Now
                    };
                    IntransitDA.InsertIntransit(dataBase, tran, intransitInfo, this.dataBaseID);
                    auditDataBLL.InsertAuditData<IntransitInfo>(dataBase, tran, null, intransitInfo, AuditAction.Insert, this.pubParasInfo.UserID, "INTRANSIT", this.dataBaseID[0]);
                }
                if (!string.IsNullOrEmpty(IntransitID))
                {
                    ordersInfo.IntransitID = IntransitID;
                }
                ordersInfo.BatchFlag = "N";
                ordersInfo.CreatedDate = DateTime.Now;
                ordersInfo.UpdatedDate = DateTime.Now;
                if (ordersDA.InsertOrders(dataBase, tran, ordersInfo, this.dataBaseID[0]) > 0)
                {
                    if (ordersInfo.ManPowerResourceInfo != null)
                    {
                        ordersInfo.ManPowerResourceInfo.OrderID = ordersInfo.OrderID;
                        ordersInfo.ManPowerResourceInfo.CreatedDate = DateTime.Now;
                        ordersInfo.ManPowerResourceInfo.UpdatedDate = DateTime.Now;
                        ManPowerResourceInfo manpowerResourceInfo = ordersInfo.ManPowerResourceInfo;
                        manpowerResourceDA.InsertManPowerResource(dataBase, tran, manpowerResourceInfo, this.dataBaseID[0]);
                    }
                    auditDataBLL.InsertAuditData<OrdersInfo>(dataBase, tran, null, ordersInfo, AuditAction.Insert, this.pubParasInfo.UserID, "ORDERS", this.dataBaseID[0]);
                    ordersID = ordersInfo.OrderID;
                }
                if (ordersInfo.IsCopy == "Y")
                {
                    if (!(tradePartnerInfo.Finance_Logistical_Ctrl == "N"))
                    {
                        throw new Exception("该货主启用了金融物流控制,不允许复制新增发货订单!");
                    }
                    orderDetailDA.IsCopyOrderDetail(dataBase, tran, ordersInfo.OrderID, ordersInfo.OldOrderID, this.pubParasInfo.UserID, this.dataBaseID[0]);
                    ordersInfo.OrderDetailInfos = orderDetailDA.GetOrderDetailListByOrderID(dataBase, tran, ordersInfo.OrderID, this.dataBaseID[0], this.pubParasInfo);
                    if (ordersInfo.OrderDetailInfos != null)
                    {
                        for (i = 0; i < ordersInfo.OrderDetailInfos.Count; i++)
                        {
                            ordersInfo.OrderDetailInfos[i].OrderID = ordersID;
                            if (!string.IsNullOrEmpty(IntransitID))
                            {
                                IntransitDetailInfo intransitDetailInfo = new IntransitDetailInfo {
                                    IntransitID = IntransitID,
                                    OrderLineID = ordersInfo.OrderDetailInfos[i].LineID,
                                    ReceiptLineID = 0,
                                    LineID = ordersInfo.OrderDetailInfos[i].LineID,
                                    OwnerID = ordersInfo.OrderDetailInfos[i].OwnerID,
                                    SkuID = ordersInfo.OrderDetailInfos[i].SkuID,
                                    UomID = ordersInfo.OrderDetailInfos[i].UomID,
                                    PackID = ordersInfo.OrderDetailInfos[i].PackID,
                                    Qty = ordersInfo.OrderDetailInfos[i].OriginalQty,
                                    ShippedQty = ordersInfo.OrderDetailInfos[i].ShippedQty,
                                    ReceivedQty = 0M,
                                    Status = IntransitStatus.New,
                                    CreatedBy = this.pubParasInfo.UserID,
                                    UpdatedBy = this.pubParasInfo.UserID
                                };
                                IntransitDetailDA.InsertIntransitDetail(dataBase, tran, intransitDetailInfo, this.dataBaseID);
                                auditDataBLL.InsertAuditData<IntransitDetailInfo>(dataBase, tran, null, intransitDetailInfo, AuditAction.Insert, this.pubParasInfo.UserID, "INTRANSIT_DETAIL", this.dataBaseID[0]);
                            }
                            auditDataBLL.InsertAuditData<OrderDetailInfo>(dataBase, tran, null, ordersInfo.OrderDetailInfos[i], AuditAction.Insert, this.pubParasInfo.UserID, "ORDER_DETAIL", this.dataBaseID[0]);
                        }
                    }
                }
                else if (((ordersInfo.IsCopy == "N") && (ordersInfo.OrderDetailInfos != null)) && (ordersInfo.OrderDetailInfos.Count > 0))
                {
                    for (i = 0; i < ordersInfo.OrderDetailInfos.Count; i++)
                    {
                        ordersInfo.OrderDetailInfos[i].OrderID = ordersID;
                        if (orderDetailDA.CheckOrderDetailIDUnique(dataBase, tran, ordersInfo.OrderDetailInfos[i].OrderID, ordersInfo.OrderDetailInfos[i].LineID.ToString(), this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F7100_006", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.OrderDetailInfos[i].OrderID, ordersInfo.OrderDetailInfos[i].LineID.ToString() });
                        }
                        else
                        {
                            ordersInfo.OrderDetailInfos[i].CreatedDate = DateTime.Now;
                            ordersInfo.OrderDetailInfos[i].UpdatedDate = DateTime.Now;
                            ordersInfo.OrderDetailInfos[i].CreatedBy = this.pubParasInfo.UserID;
                            ordersInfo.OrderDetailInfos[i].UpdatedBy = this.pubParasInfo.UserID;
                            orderDetailDA.InsertOrderDetail(dataBase, tran, ordersInfo.OrderDetailInfos[i], this.dataBaseID[0]);
                            auditDataBLL.InsertAuditData<OrderDetailInfo>(dataBase, tran, null, ordersInfo.OrderDetailInfos[i], AuditAction.Insert, this.pubParasInfo.UserID, "ORDER_DETAIL", this.dataBaseID[0]);
                        }
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ordersID;
        }

        public string OrderTrackingImportByData(string[][] ImportByData)
        {
            Exception ex;
            try
            {
                string whLoginID = this.dataBaseID[0];
                List<OrdersInfo> ordersInfoList = new List<OrdersInfo>();
                for (int i = 1; i < ImportByData.Length; i++)
                {
                    OrdersInfo ordersInfo = new OrdersInfo {
                        CreatedBy = this.pubParasInfo.UserID,
                        UpdatedBy = this.pubParasInfo.UserID
                    };
                    for (int j = 0; j < ImportByData[i].Length; j++)
                    {
                        switch (ImportByData[0][j].ToUpper().Trim())
                        {
                            case "订单号*":
                            {
                                ordersInfo.OrderID = ImportByData[i][j];
                                continue;
                            }
                            case "投递状态*":
                            {
                                ordersInfo.Status = ImportByData[i][j];
                                continue;
                            }
                            case "操作时间*":
                            {
                                if (string.IsNullOrEmpty(ImportByData[i][j]))
                                {
                                    break;
                                }
                                ordersInfo.OperatingDate = DateTime.Parse(ImportByData[i][j]);
                                continue;
                            }
                            case "操作人*":
                            {
                                ordersInfo.Operator = ImportByData[i][j];
                                continue;
                            }
                            case "承运商代码*":
                            {
                                ordersInfo.CarrierID = ImportByData[i][j];
                                continue;
                            }
                            case "承运商名称":
                            {
                                ordersInfo.CarrierName = ImportByData[i][j];
                                continue;
                            }
                            case "异常原因":
                            {
                                ordersInfo.Abnormal = ImportByData[i][j];
                                continue;
                            }
                            case "处理方式":
                            {
                                ordersInfo.Handling = ImportByData[i][j];
                                continue;
                            }
                            default:
                            {
                                continue;
                            }
                        }
                        ordersInfo.OperatingDate = DateTime.Now;
                    }
                    if (((string.IsNullOrEmpty(ordersInfo.OrderID) || string.IsNullOrEmpty(ordersInfo.Status)) || (string.IsNullOrEmpty(ordersInfo.Operator) || string.IsNullOrEmpty(ordersInfo.CarrierID))) || string.IsNullOrEmpty(ordersInfo.OperatingDate.ToString()))
                    {
                        throw new Exception("有必输项为空,请重新导入!");
                    }
                    if (((ordersInfo.Status != "正常妥投") && (ordersInfo.Status != "客户拒收")) && !(ordersInfo.Status == "全部丢失"))
                    {
                        throw new Exception("投递状态" + ordersInfo.Status + "不存在或超出范围!");
                    }
                    if (ordersInfo.Status == "正常妥投")
                    {
                        ordersInfo.Status = "Delivery";
                    }
                    else if (ordersInfo.Status == "客户拒收")
                    {
                        ordersInfo.Status = "Rejected";
                    }
                    else
                    {
                        ordersInfo.Status = "Lost";
                    }
                    if (!vendorDA.CheckVendorIDUnique(ordersInfo.CarrierID, whLoginID))
                    {
                        throw new Exception("承运商" + ordersInfo.CarrierID + "不存在!");
                    }
                    OrdersInfo orderInfo = ordersDA.GetOrdersByID(ordersInfo.OrderID, whLoginID, this.pubParasInfo);
                    if (orderInfo == null)
                    {
                        throw new Exception("单据" + ordersInfo.OrderID + "不存在!");
                    }
                    if ((orderInfo.Status.ToUpper() != "PARTSHIPPED") && !(orderInfo.Status.ToUpper() == "SHIPPED"))
                    {
                        throw new Exception("单据" + ordersInfo.OrderID + "不是发货完成或者部分发货状态,不能更新投递状态!");
                    }
                    ordersInfoList.Add(ordersInfo);
                }
                if ((ordersInfoList != null) && (ordersInfoList.Count > 0))
                {
                    DataBase dataBase = new DataBase();
                    DbConnection conn = dataBase.connection;
                    conn.Open();
                    DbTransaction tran = conn.BeginTransaction();
                    try
                    {
                        foreach (OrdersInfo info in ordersInfoList)
                        {
                            ordersDA.UpdateOrderTracking(dataBase, tran, info.OrderID, info.Status, info.Operator, info.OperatingDate, info.Abnormal, info.Handling, info.UpdatedBy, whLoginID);
                            orderDetailDA.UpdateOrderDetailOrderTrackingByID(dataBase, tran, info.OrderID, info.Status, whLoginID);
                        }
                        tran.Commit();
                    }
                    catch (Exception exception1)
                    {
                        ex = exception1;
                        tran.Rollback();
                        CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            catch (Exception exception2)
            {
                ex = exception2;
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return "";
        }

        public string UpdateOrdersByShippingWeight(OrdersInfo ordersInfo)
        {
            string ordersID = string.Empty;
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            try
            {
                OrdersInfo oldOrdersInfo = ordersDA.GetOrdersByID(ordersInfo.OrderID, this.dataBaseID[0], this.pubParasInfo);
                ordersInfo.UpdatedBy = this.pubParasInfo.UserID;
                ordersInfo.UpdatedDate = DateTime.Now;
                if (ordersDA.UpdateOrdersByShippingWeight(ordersInfo, this.dataBaseID[0]) > 0)
                {
                    auditDataBLL.InsertAuditData<OrdersInfo>(oldOrdersInfo, ordersInfo, AuditAction.Update, this.pubParasInfo.UserID, "ORDERS", this.dataBaseID[0]);
                    ordersID = ordersInfo.OrderID;
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return ordersID;
        }

        public string UpdateOrdersIsCancel(string orderid, string isCancel)
        {
            string ordersID = string.Empty;
            try
            {
                if (ordersDA.UpdateOrdersIsCancel(orderid, isCancel, this.dataBaseID[0], this.pubParasInfo) > 0)
                {
                    ordersID = orderid;
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return ordersID;
        }

        public string UpdateOrdersPackingType(List<string> orderID, string packingType)
        {
            string ordersID = string.Empty;
            try
            {
                for (int i = 0; orderID.Count > i; i++)
                {
                    if (ordersDA.UpdateOrdersPackingType(orderID[i], packingType, this.dataBaseID[0], this.pubParasInfo) > 0)
                    {
                        ordersID = ordersID + orderID[i];
                    }
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return ordersID;
        }

        public string UpdateOrderStatusByOrderID(List<string> orderIDList, string ordersStatus, string operators, DateTime operatingDate, string abnormal, string handling, List<string> lineID, List<decimal> numberLost)
        {
            string strWhLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string ordersID = string.Empty;
            try
            {
                for (int i = 0; orderIDList.Count > i; i++)
                {
                    if (ordersDA.UpdateOrderTracking(dataBase, tran, orderIDList[i], ordersStatus, operators, operatingDate, abnormal, handling, this.pubParasInfo.UserID, strWhLoginID) > 0)
                    {
                        string CS40002 = ordersStatus;
                        if (CS40002 != null)
                        {
                            if ((!(CS40002 == "Delivery") && !(CS40002 == "Lost")) && (!(CS40002 == "Rejected") && !(CS40002 == "Settlement")))
                            {
                                if (CS40002 == "PartLost")
                                {
                                    goto Label_00DA;
                                }
                            }
                            else
                            {
                                orderDetailDA.UpdateOrderDetailOrderTrackingByID(dataBase, tran, orderIDList[i], ordersStatus, strWhLoginID);
                            }
                        }
                    }
                    goto Label_00F7;
                Label_00DA:
                    orderDetailDA.UpdateOrderDetailPartLostByID(dataBase, tran, orderIDList[i], lineID, numberLost, strWhLoginID);
                Label_00F7:
                    ordersID = ordersID + orderIDList[i] + "/";
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ordersID;
        }

        public string UpdateOrdres(OrdersInfo ordersInfo)
        {
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            string ordersID = string.Empty;
            AuditDataBLL auditDataBLL = new AuditDataBLL();
            try
            {
                if (!string.IsNullOrEmpty(ordersInfo.CarrierID))
                {
                    if (!carrierDA.CheckCarrierIDUnique(dataBase, tran, ordersInfo.CarrierID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_001", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.CarrierID });
                    }
                    else if (!carrierDA.CheckAuthorizationCarrierUserID(dataBase, tran, ordersInfo.CarrierID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2140_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.CarrierID });
                    }
                }
                if (!string.IsNullOrEmpty(ordersInfo.DestinationPort) && !portDA.CheckPortIDUnique(dataBase, tran, ordersInfo.DestinationPort, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2140_004", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.DestinationPort });
                }
                if (!string.IsNullOrEmpty(ordersInfo.DeparturePort) && !portDA.CheckPortIDUnique(dataBase, tran, ordersInfo.DeparturePort, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F2140_005", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.DeparturePort });
                }
                if (!string.IsNullOrEmpty(ordersInfo.ConsigneeID))
                {
                    if (string.Compare(ordersInfo.Type, "Return", true) == 0)
                    {
                        if (!vendorDA.CheckVendorIDUnique(dataBase, tran, ordersInfo.ConsigneeID, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F4200_006", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                        }
                        else if (!vendorDA.CheckAuthorizationVendorIDUserID(dataBase, tran, ordersInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2130_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                        }
                    }
                    else if (ordersInfo.Type != OrderTypes.Transfer)
                    {
                        if (!customerDA.CheckCustomerIDUnique(dataBase, tran, ordersInfo.ConsigneeID, this.dataBaseID[0]))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2120_001", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                        }
                        else if (!customerDA.CheckAuthorizationCustomerIDUserID(dataBase, tran, ordersInfo.ConsigneeID, this.dataBaseID[0], this.pubParasInfo))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F2120_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.ConsigneeID });
                        }
                    }
                }
                if (!string.IsNullOrEmpty(ordersInfo.BillToID))
                {
                    if (!billingEntityDA.CheckBillingEntityIDUnique(dataBase, tran, ordersInfo.BillToID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2150_001", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.BillToID });
                    }
                    else if (!billingEntityDA.CheckAuthorizationBillingEntityUserID(dataBase, tran, ordersInfo.BillToID, this.pubParasInfo, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2150_002", this.pubParasInfo.UserLanguage, new List<string> { ordersInfo.BillToID });
                    }
                }
                IntransitInfo tempIntransitInfo = IntransitDA.GetIntransitByOrderID(dataBase, tran, ordersInfo.OrderID, this.dataBaseID[0]);
                if (!((tempIntransitInfo == null) || string.IsNullOrEmpty(tempIntransitInfo.IntransitID)))
                {
                    IntransitInfo intransitInfo = new IntransitInfo();
                    intransitInfo = tempIntransitInfo;
                    intransitInfo.ExpectedReceiptDate = ordersInfo.DeliveryDate;
                    intransitInfo.ActualShipDate = ordersInfo.ActualShipDate;
                    intransitInfo.UpdatedBy = ordersInfo.UpdatedBy;
                    IntransitDA.UpdateIntransit(dataBase, tran, intransitInfo, this.dataBaseID);
                    auditDataBLL.InsertAuditData<IntransitInfo>(dataBase, tran, tempIntransitInfo, intransitInfo, AuditAction.Update, this.pubParasInfo.UserID, "INTRANSIT", this.dataBaseID[0]);
                }
                OrdersInfo oldOrdersInfo = ordersDA.GetOrdersByID(dataBase, tran, ordersInfo.OrderID, this.dataBaseID[0], this.pubParasInfo);
                ordersInfo.UpdatedBy = ordersInfo.CreatedBy;
                ordersInfo.UpdatedDate = DateTime.Now;
                if (ordersDA.UpdateOrders(dataBase, tran, ordersInfo, this.dataBaseID[0]) > 0)
                {
                    if (ordersInfo.ManPowerResourceInfo != null)
                    {
                        ManPowerResourceInfo manpowerResourceInfo = ordersInfo.ManPowerResourceInfo;
                        if (manpowerResourceDA.CheckManPowerResourceUnique(manpowerResourceInfo.OrderID, manpowerResourceInfo.OrderType, this.dataBaseID[0]))
                        {
                            manpowerResourceInfo.UpdatedDate = DateTime.Now;
                            manpowerResourceDA.UpdateManPowerResource(manpowerResourceInfo, this.dataBaseID[0]);
                        }
                        else
                        {
                            manpowerResourceInfo.OrderID = ordersInfo.OrderID;
                            manpowerResourceInfo.CreatedDate = DateTime.Now;
                            manpowerResourceInfo.UpdatedDate = DateTime.Now;
                            manpowerResourceDA.InsertManPowerResource(manpowerResourceInfo, this.dataBaseID[0]);
                        }
                    }
                    auditDataBLL.InsertAuditData<OrdersInfo>(dataBase, tran, oldOrdersInfo, ordersInfo, AuditAction.Update, this.pubParasInfo.UserID, "ORDERS", this.dataBaseID[0]);
                    ordersID = ordersInfo.OrderID;
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return ordersID;
        }
    }
}

